import createAxios from '@lib/shared/api/http';
import useAgentApi from '@lib/shared/api/modules/agent';
import useClueApi from '@lib/shared/api/modules/clue';
import useContractApi from '@lib/shared/api/modules/contract';
import useCustomerApi from '@lib/shared/api/modules/customer';
import useDashboard from '@lib/shared/api/modules/dashboard';
import useFollowApi from '@lib/shared/api/modules/follow';
import useHomeApi from '@lib/shared/api/modules/home';
import useOpportunityApi from '@lib/shared/api/modules/opportunity';
import useProductApi from '@lib/shared/api/modules/product';
import useSysApi from '@lib/shared/api/modules/sys';
import useLicenseApi from '@lib/shared/api/modules/system/authorizedManagement';
import useBusinessApi from '@lib/shared/api/modules/system/business';
import useLoginApi from '@lib/shared/api/modules/system/login';
import useMessageApi from '@lib/shared/api/modules/system/message';
import useModuleApi from '@lib/shared/api/modules/system/module';
import useOrgApi from '@lib/shared/api/modules/system/org';
import useRoleApi from '@lib/shared/api/modules/system/role';

import useDiscreteApi from '@/hooks/useDiscreteApi';

import checkStatus from '../http/checkStatus';

const { message } = useDiscreteApi();

const CDR = createAxios({
  showErrorMsg: message.error,
  checkStatus,
});

const orgApi = useOrgApi(CDR);
const sysApi = useSysApi(CDR);
const clueApi = useClueApi(CDR);
const roleApi = useRoleApi(CDR);
const homeApi = useHomeApi(CDR);
const loginApi = useLoginApi(CDR);
const agentApi = useAgentApi(CDR);
const moduleApi = useModuleApi(CDR);
const followApi = useFollowApi(CDR);
const productApi = useProductApi(CDR);
const messageApi = useMessageApi(CDR);
const licenseApi = useLicenseApi(CDR);
const customerApi = useCustomerApi(CDR);
const businessApi = useBusinessApi(CDR);
const dashboardApi = useDashboard(CDR);
const opportunityApi = useOpportunityApi(CDR);
const contractApi = useContractApi(CDR);

export const {
  getFollowPlanTab,
  deleteFollowPlan,
  updateFollowPlan,
  getFollowPLanPage,
  addFollowPlanView,
  deleteFollowRecord,
  getFollowRecordTab,
  updateFollowRecord,
  dragFollowPlanView,
  getFollowPlanDetail,
  getFollowRecordPage,
  addFollowRecordView,
  fixedFollowPlanView,
  dragFollowRecordView,
  updateFollowPlanView,
  enableFollowPlanView,
  deleteFollowPlanView,
  getFollowRecordDetail,
  fixedFollowRecordView,
  getFollowPlanViewList,
  updateFollowPlanStatus,
  updateFollowRecordView,
  enableFollowRecordView,
  deleteFollowRecordView,
  getFollowRecordViewList,
  getFollowPlanViewDetail,
  getFollowRecordViewDetail,
} = followApi;

export const {
  addProduct,
  getProduct,
  deleteProduct,
  updateProduct,
  importProduct,
  getProductList,
  dragSortProduct,
  getProductOptions,
  batchDeleteProduct,
  batchUpdateProduct,
  getProductFormConfig,
  preCheckImportProduct,
  downloadProductTemplate,
  getProductPrice,
  updateProductPrice,
  getProductPriceList,
  addProductPrice,
  deleteProductPrice,
  getProductPriceFormConfig,
  dragSortProductPrice,
  batchUpdateProductPrice,
  downloadProductPriceTemplate,
  exportProductPriceAll,
  exportProductPriceSelected,
  preCheckImportProductPrice,
  importProductPrice,
} = productApi;

export const {
  deleteOpt,
  getOptTab,
  transferOpt,
  addOpportunity,
  batchDeleteOpt,
  updateOptStage,
  addBusinessView,
  getOptStatistic,
  sortOpportunity,
  getOptFormConfig,
  addOptFollowPlan,
  getOptFollowPlan,
  dragBusinessView,
  updateOpportunity,
  fixedBusinessView,
  preCheckImportOpt,
  importOpportunity,
  getOpportunityList,
  addOptFollowRecord,
  getOptFollowRecord,
  deleteBusinessView,
  updateBusinessView,
  enableBusinessView,
  updateOptFollowPlan,
  deleteOptFollowPlan,
  cancelOptFollowPlan,
  getBusinessViewList,
  globalSearchOptPage,
  downloadOptTemplate,
  addOpportunityStage,
  getOpportunityDetail,
  getOptFollowPlanList,
  exportOpportunityAll,
  sortOpportunityStage,
  deleteOptFollowRecord,
  updateOptFollowRecord,
  getBusinessViewDetail,
  advancedSearchOptPage,
  getOptFollowRecordList,
  batchUpdateOpportunity,
  updateOpportunityStage,
  deleteOpportunityStage,
  advancedSearchOptDetail,
  generateOpportunityChart,
  getOpportunityContactList,
  updateOptFollowPlanStatus,
  exportOpportunitySelected,
  getOpportunityStageConfig,
  updateOpportunityStageRollback,
  getQuotationTab,
  addQuotationView,
  deleteQuotationView,
  fixedQuotationView,
  getQuotationViewDetail,
  getQuotationViewList,
  updateQuotationView,
  enableQuotationView,
  dragQuotationView,
  getQuotationList,
  addQuotation,
  updateQuotation,
  getQuotationDetail,
  getQuotationFormConfig,
  getQuotationSnapshotFormConfig,
  deleteQuotation,
  approvalQuotation,
  voidQuotation,
  revokeQuotation,
  batchApprove,
  batchVoided,
  downloadQuotation,
} = opportunityApi;

export const {
  addClue,
  getClue,
  pickClue,
  updateClue,
  deleteClue,
  assignClue,
  getClueTab,
  importLead,
  getClueList,
  getPoolClue,
  addClueView,
  dragClueView,
  batchPickClue,
  exportClueAll,
  fixedClueView,
  transformClue,
  getPoolOptions,
  deleteCluePool,
  moveToLeadPool,
  deleteClueView,
  updateClueView,
  enableClueView,
  batchToCluePool,
  batchDeleteClue,
  getCluePoolList,
  batchAssignClue,
  getClueViewList,
  addLeadPoolView,
  batchUpdateLead,
  updateClueStatus,
  dragLeadPoolView,
  batchTransferClue,
  getClueFormConfig,
  addClueFollowPlan,
  getClueFollowPlan,
  getClueHeaderList,
  getClueViewDetail,
  exportCluePoolAll,
  fixedLeadPoolView,
  generateLeadChart,
  exportClueSelected,
  preCheckImportLead,
  deleteLeadPoolView,
  updateLeadPoolView,
  enableLeadPoolView,
  addClueFollowRecord,
  getClueFollowRecord,
  batchDeleteCluePool,
  batchUpdateCluePool,
  getLeadPoolViewList,
  reTransitionCustomer,
  updateClueFollowPlan,
  deleteClueFollowPlan,
  cancelClueFollowPlan,
  downloadLeadTemplate,
  getClueFollowPlanList,
  getGlobalCluePoolList,
  getLeadPoolViewDetail,
  generateLeadPoolChart,
  ClueTransitionCustomer,
  updateClueFollowRecord,
  deleteClueFollowRecord,
  exportCluePoolSelected,
  getClueFollowRecordList,
  getAdvancedCluePoolList,
  getGlobalSearchClueList,
  getAdvancedSearchClueList,
  updateClueFollowPlanStatus,
  getCluePoolFollowRecordList,
  getAdvancedSearchClueDetail,
  getClueTransitionCustomerList,
} = clueApi;

export const {
  addCustomer,
  getCustomer,
  mergeAccount,
  importAccount,
  importContact,
  updateCustomer,
  deleteCustomer,
  getCustomerTab,
  addContactView,
  getCustomerList,
  addCustomerView,
  dragContactView,
  checkOpportunity,
  fixedContactView,
  dragCustomerView,
  exportContactAll,
  mergeAccountPage,
  batchMoveCustomer,
  getOpenSeaOptions,
  exportCustomerAll,
  fixedCustomerView,
  deleteContactView,
  updateContactView,
  enableContactView,
  addCustomerContact,
  getCustomerContact,
  addCustomerOpenSea,
  getOpenSeaCustomer,
  getCustomerOptions,
  moveCustomerToPool,
  deleteCustomerView,
  updateCustomerView,
  enableCustomerView,
  getContactViewList,
  addAccountPoolView,
  batchUpdateAccount,
  batchUpdateContact,
  batchDeleteCustomer,
  pickOpenSeaCustomer,
  getCustomerViewList,
  dragAccountPoolView,
  saveCustomerRelation,
  getContactViewDetail,
  getGlobalModuleCount,
  fixedAccountPoolView,
  getCustomerFormConfig,
  batchTransferCustomer,
  addCustomerFollowPlan,
  getCustomerFollowPlan,
  updateCustomerContact,
  enableCustomerContact,
  deleteCustomerContact,
  updateCustomerOpenSea,
  switchCustomerOpenSea,
  deleteCustomerOpenSea,
  assignOpenSeaCustomer,
  deleteOpenSeaCustomer,
  getCustomerHeaderList,
  getCustomerContactTab,
  getCustomerViewDetail,
  getGlobalCustomerList,
  exportContactSelected,
  preCheckImportAccount,
  preCheckImportContact,
  deleteAccountPoolView,
  updateAccountPoolView,
  enableAccountPoolView,
  generateCustomerChart,
  getCustomerContactList,
  disableCustomerContact,
  getCustomerOpenSeaList,
  getOpenSeaCustomerList,
  exportCustomerSelected,
  geAdvancedCustomerList,
  getAccountPoolViewList,
  addCustomerFollowRecord,
  getCustomerFollowRecord,
  isCustomerOpenSeaNoPick,
  getCustomerRelationList,
  downloadAccountTemplate,
  downloadContactTemplate,
  updateCustomerFollowPlan,
  deleteCustomerFollowPlan,
  cancelCustomerFollowPlan,
  batchPickOpenSeaCustomer,
  addCustomerCollaboration,
  exportCustomerOpenSeaAll,
  getAccountPoolViewDetail,
  getCustomerFollowPlanList,
  generateCustomerPoolChart,
  updateCustomerFollowRecord,
  deleteCustomerFollowRecord,
  batchDeleteOpenSeaCustomer,
  batchAssignOpenSeaCustomer,
  getCustomerOpportunityPage,
  batchUpdateOpenSeaCustomer,
  getCustomerFollowRecordList,
  getContactListUnderCustomer,
  updateCustomerCollaboration,
  deleteCustomerCollaboration,
  getCustomerContactFormConfig,
  getCustomerCollaborationList,
  getGlobalOpenSeaCustomerList,
  getGlobalCustomerContactList,
  generateCustomerContactChart,
  exportCustomerOpenSeaSelected,
  updateCustomerFollowPlanStatus,
  getAdvancedCustomerContactList,
  getAdvancedOpenSeaCustomerList,
  getCustomerFollowPlanFormConfig,
  batchDeleteCustomerCollaboration,
  getCustomerFollowRecordFormConfig,
  getCustomerOpenSeaFollowRecordList,
  getAccountContract,
  getAccountContractStatistic,
  getAccountPayment,
  getAccountPaymentStatistic,
} = customerApi;

export const {
  exportContractAll,
  exportContractSelected,
  generateContractChart,
  getContractDetail,
  getContractList,
  getContractTab,
  getContractViewDetail,
  getContractViewList,
  addContractView,
  updateContractView,
  fixedContractView,
  enableContractView,
  deleteContractView,
  dragContractView,
  addContract,
  voidedContract,
  archivedContract,
  approvalContract,
  batchApproveContract,
  getContractFormSnapshotConfig,
  updateContract,
  deleteContract,
  changeContractStatus,
  getContractFormConfig,
  getPaymentPlanList,
  getContractPaymentPlanList,
  addPaymentPlan,
  updatePaymentPlan,
  deletePaymentPlan,
  getPaymentPlanDetail,
  getPaymentPlanFormConfig,
  getPaymentPlanTab,
  exportPaymentPlanAll,
  exportPaymentPlanSelected,
  generatePaymentPlanChart,
  addPaymentPlanView,
  updatePaymentPlanView,
  getPaymentPlanViewList,
  getPaymentPlanViewDetail,
  fixedPaymentPlanView,
  enablePaymentPlanView,
  deletePaymentPlanView,
  dragPaymentPlanView,
} = contractApi;

export const {
  syncDE,
  addApiKey,
  updateAuth,
  createAuth,
  deleteAuth,
  getDEToken,
  getAuthList,
  getDEOrgList,
  updateApiKey,
  enableApiKey,
  deleteApiKey,
  getAuthDetail,
  sendEmailCode,
  getApiKeyList,
  disableApiKey,
  getPageConfig,
  getConfigEmail,
  updateAuthName,
  savePageConfig,
  testConfigEmail,
  getPersonalInfo,
  getThirdTypeList,
  switchThirdParty,
  updateAuthStatus,
  updateConfigEmail,
  getPersonalFollow,
  updatePersonalInfo,
  updateUserPassword,
  cancelCenterExport,
  getExportCenterList,
  getThirdPartyConfig,
  getThirdConfigByType,
  exportCenterDownload,
  getThirdPartyResource,
  getConfigSynchronization,
  testConfigSynchronization,
  updateConfigSynchronization,
  getTenderConfig,
} = businessApi;

export const {
  getMessageTask,
  addAnnouncement,
  saveMessageTask,
  updateAnnouncement,
  deleteAnnouncement,
  getHomeMessageList,
  getAnnouncementList,
  getNotificationList,
  setNotificationRead,
  getNotificationCount,
  batchSaveMessageTask,
  getAnnouncementDetail,
  closeMessageSubscribe,
  getUnReadAnnouncement,
  setAllNotificationRead,
} = messageApi;

export const {
  addReason,
  sortReason,
  addCluePool,
  addCapacity,
  checkRepeat,
  updateReason,
  searchConfig,
  getReasonList,
  updateCluePool,
  noPickCluePool,
  updateCapacity,
  deleteCapacity,
  uploadTempFile,
  previewPicture,
  getCluePoolPage,
  getCapacityPage,
  addCustomerPool,
  downloadPicture,
  getReasonConfig,
  getSearchConfig,
  getFieldDeptTree,
  getFieldClueList,
  getFieldContractList,
  deleteReasonItem,
  deleteAttachment,
  moduleNavListSort,
  getModuleRoleTree,
  deleteOpportunity,
  resetSearchConfig,
  setTopNavListSort,
  previewAttachment,
  addOpportunityRule,
  updateCustomerPool,
  deleteCustomerPool,
  noPickCustomerPool,
  updateReasonEnable,
  downloadAttachment,
  getCustomerPoolPage,
  getFormDesignConfig,
  getFieldDeptUerTree,
  getFieldContactList,
  getFieldProductList,
  getModuleTopNavList,
  switchCluePoolStatus,
  deleteModuleCluePool,
  saveFormDesignConfig,
  getFieldCustomerList,
  uploadTempAttachment,
  toggleModuleNavStatus,
  getModuleUserDeptTree,
  updateOpportunityRule,
  getModuleNavConfigList,
  getOpportunityRuleList,
  moduleSearchMaskConfig,
  switchOpportunityStatus,
  getFieldOpportunityList,
  switchCustomerPoolStatus,
  getModuleSearchMaskConfig,
  getFieldPriceList,
  getFieldQuotationList,
  getFieldDisplayList,
} = moduleApi;

export const {
  addUser,
  syncOrg,
  updateUser,
  deleteUser,
  getUserList,
  importUsers,
  setCommander,
  addDepartment,
  getUserDetail,
  batchEditUser,
  getUserOptions,
  getRoleOptions,
  sortDepartment,
  deleteUserCheck,
  renameDepartment,
  deleteDepartment,
  getDepartmentTree,
  resetUserPassword,
  updateOrgUserName,
  importUserPreCheck,
  getOrgDepartmentUser,
  batchToggleStatusUser,
  checkDeleteDepartment,
  batchResetUserPassword,
  checkSyncUserFromThird,
} = orgApi;

export const {
  getRoles,
  getUsers,
  updateRole,
  createRole,
  deleteRole,
  getRoleMember,
  getRoleDetail,
  getPermissions,
  getRoleDeptTree,
  relateRoleMember,
  removeRoleMember,
  getRoleMemberTree,
  getRoleDeptUserTree,
  batchRemoveRoleMember,
} = roleApi;

export const { login, signout, isLogin, getKey, getThirdCallback, getThirdOauthCallback } = loginApi;

export const { getSystemVersion, changeLocaleBackEnd } = sysApi;

export const { getLicense, addLicense } = licenseApi;

export const {
  dashboardAdd,
  dashboardPage,
  dashboardDrag,
  dashboardDelete,
  dashboardDetail,
  dashboardRename,
  dashboardUpdate,
  dashboardCollect,
  dashboardModuleAdd,
  dashboardUnCollect,
  dashboardModuleTree,
  dashboardModuleDrag,
  dashboardCollectPage,
  dashboardModuleCount,
  dashboardModuleDelete,
  dashboardModuleRename,
} = dashboardApi;

export const { getHomeDepartmentTree, getHomeFollowOpportunity, getHomeLeadStatistic, getHomeSuccessOptStatistic } =
  homeApi;

export const {
  addAgent,
  agentPos,
  updateAgent,
  agentRename,
  agentDelete,
  getAgentPage,
  agentCollect,
  agentModuleAdd,
  unCollectAgent,
  getAgentDetail,
  agentModuleMove,
  getAgentOptions,
  agentModuleRename,
  agentModuleDelete,
  getMkAgentVersion,
  getAgentModuleTree,
  getAgentCollectPage,
  getApplicationScript,
  agentWorkspaceOptions,
  getAgentModuleTreeCount,
  agentApplicationOptions,
  getMkApplication,
} = agentApi;
